#!/bin/sh
##############################################################################
# This program recompiles consciousness and gen_partitions
# USAGE:
# ./recompile [-fast]
# 
# The user can specify an optional argument '-fast' which compiles for speed
##############################################################################

# default aguments to g++
output_filename="consciousness"

# sometimes you can get a speedup by enabling -fopenmp
#libs="-I/usr/local/boost -I/usr/local/lib -fopenmp"
libs="-I/usr/local/boost -I/usr/local/lib"

# you can enable $extra_args -v option for debugging
#extra_args="-v"
extra_args=""

# if the user specified '-fast' as a parameter change the compile-time arguments
if [[ "$1" == "-fast" || "$1" == "-f" || "$2" == "-fast" || "$2" == "-f" ]]
then

	# This is for APPLE COMPUTERS ONLY
	if [[ "$(uname -s)" == "Darwin" ]]
	then
		extra_args="$extra_args -fast"
	# if you're not using an mac, use this
	else
		extra_args="$extra_args -O3 -fomit-frame-pointer"
#		extra_args="-Os -fomit-frame-pointer"
	fi
fi

# if we have extra args, print them
if [[ "$extra_args" != "" ]]
then
	echo "-- compiling with '$extra_args'"
fi

# compile consciousness
echo "- compiling $output_filename..."
g++ consc/helpers.cpp consc/t_state.cpp consc/t_consc.cpp consc/t_partition.cpp consc/t_subset.cpp consc/PartitionEnumerator.cpp consc/main.cpp $libs $extra_args -o $output_filename



if [[ "$1" == "-g"  || "$2" == "-g" ]]
then
	# compile the program that generates the partitions on the fly
	echo "- compiling gen_partitions..."
	g++ gen_partitions.cpp consc/t_state.cpp consc/helpers.cpp consc/t_consc.cpp consc/t_subset.cpp consc/t_partition.cpp consc/PartitionEnumerator.cpp $libs $extra_args -o gen_partitions
fi

echo "Done!"
